<?php
class Model_Product_Mapper extends App_Model_Mapper
{
	protected $_map = array(
    	   'id'          =>'id',
           'brand'       =>'brand',
           'category'    =>'category',
           'class'       =>'class',
           'material'    =>'material',
           'gender'      =>'gender',
           'size'        =>'size',
           'season'      =>'season',
           'delivery'    =>'delivery',
           'category_id' =>'category_id',
    	   'price'       =>'price'
       );
       protected $_entityClass = 'Model_Product';

       protected function _setTable()
       {
        return new Model_DbTable_Product();
       }
       
       public function getCategory(Model_Product $product)
       {
           $categoryMapper = new Model_Category_Mapper();
           return $categoryMapper->load($product->category_id);
       }
       
       public function getSimilar(Model_Product $product)
       {
           $select = $this->_table->select()->where($this->_map['category_id'] . ' = ' . $product->category_id)
                ->where("{$this->_map['size']} between $product->size-2 and $product->size + 2")
                ->order('RAND()')
                ->limit(12);
           return $this->getArray($this->_table->fetchAll($select));
       }
}